<?	
	if($_SESSION['is_login'] != true){ header("Location: ".$root."/dang-nhap/");}
	if(isset($_SESSION['uid'])){$uid = $_SESSION['uid'];}
	
	if( (isset($_GET['act'])) && ($_GET['act'] == 'delete') ){
		if(isset($_GET['pid'])){
			$pid = intval($_GET['pid']);

			$rs = $db->query("SELECT u_sanphamluu FROM ".$prefix."nguoidung WHERE u_id = '".$uid."' AND u_banned = 1");
			if($db->num_rows($rs) != 0){
				$row = $db->fetch_array($rs);
				$u_sanphamluu = split(";",$row[u_sanphamluu]);
				$tmp = "";
				$st = 0;
				for($i=0;$i<count($u_sanphamluu);$i++){
					$st++;
					if($u_sanphamluu[$i] != $pid){
						$s = count($u_sanphamluu)-1;
						if($st !=  $s){
							$tmp .= $u_sanphamluu[$i] . ";";
						}else{
							$tmp .= $u_sanphamluu[$i];
						}
					}
				}
				$db->query("UPDATE ".$prefix."nguoidung SET u_sanphamluu = '".$tmp."' WHERE u_id = '".$uid."' AND u_banned = 1");
				reHome($urlHome);
			}else{
				reHome($urlHome);
			}
		}
	}
?>
<div id="linkPath">
<div class="linkPath">
    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>

    </div>
    <div class="corner-round-01-body">    
       
	    <?
			file_exist('includes/inc_thong_tin_rieng.php');
			include('includes/inc_thong_tin_rieng.php');	
		?>

        <div style="clear: both;"></div>
    </div>
    <div class="corner-round-01-bottom-right">
        <div class="corner-round-01-bottom-left">
            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>
    </div>

    <!-- Main Page-Content { -->    
    <div id="page-content">            
        <div id="page-content-lpane">                        
            <!-- Menu Left { -->
            <div id="menuleft" class="menucategory">
                <div class="category-header-right menucategory">
                    <div class="category-header-left">
                        <div class="category-header-bg" style="text-align:left;padding-left:10px">
                            <p>Chức năng</p>
                        </div>

                    </div>
                </div> 
                <div class="corner-round-05-top-right"><div class="corner-round-05-top-left"><div class="corner-round-05-top-bg"></div></div></div>
                <div class="corner-round-05-body">        
                    <div id="product-category">                        
                        <div class="category-items-filters">
                            Sản phẩm đã lưu
                        </div>
                    </div>
                    <div style="height:10px"></div>        
                </div>

                <div class="corner-round-05-bottom-right">
                    <div class="corner-round-05-bottom-left">
                        <div class="corner-round-05-bottom-bg"></div>
                    </div>
                </div>
                <br />
            </div>
            <!-- } Menu Left -->
        </div>

        <div id="page-content-mpane-all">
 
 <?
 	$rs = $db->query("SELECT u_sanphamluu FROM ".$prefix."nguoidung WHERE u_id = '".$uid."' AND u_banned = 1");
	if($db->num_rows($rs) != 0){
		$row = $db->fetch_array($rs);
		$u_sanphamluu = str_replace(";",",",$row[u_sanphamluu]);
	}else{
		reHome($urlHome);
	}
	/////LOad sanpham 
	$sosanpham = 0;
	if($u_sanphamluu != ""){
		$sql = "SELECT * FROM ".$prefix."sanpham WHERE t_id IN(".$u_sanphamluu.")";
		if(isset($_GET['sid'])){
			$sid = intval($_GET['sid']);
			if($sid == 1){
				$sql .= " ORDER BY t_id DESC";
			}else if($sid == 2){
				$sql .= " ORDER BY t_id DESC";
			}else if($sid == 3){
				$sql .= " ORDER BY t_giaban ASC";
			}else if($sid == 4){
				$sql .= " ORDER BY t_giaban ASC";
			}else{
				$sql = $sql;
			}
		}
		
		$pp=10; 
		$parr=array();
		$parr=paging($sql,$pp);
		$page=$parr[0];
		$limitvalue=$parr[1];
		$numofpages=$parr[2];
		$sql.=" LIMIT $limitvalue, $pp";
		
		$rs = $db->query($sql);
		$sosanpham = $db->num_rows($rs);
	}
 ?> 
  <script language="javascript">
  	function funSapXep(id){
		window.location='<?=$root?>/?mod=sanphamluu&sid=' + id;
	}
  </script>         
<!-- Product List { -->
<div id="filtersDescription">
    <div class="corner-round-04-top-right">
        <div class="corner-round-04-top-left">
            <div class="corner-round-04-top-bg"></div>
        </div>

    </div>
    <div class="corner-round-04-body" style="height:20px;">         
        <ul id="descriptionBar" style="margin:0px;">
            <li style="float:left;margin:0px;line-height:20px;">
                Tổng cộng <b><?=$sosanpham?></b> sản phẩm
            </li>
            <li style="float:right;margin:0px;line-height:20px;" id="menuContainer">                                 
                Sắp xếp theo: 
				<select name="sapxep" id="sapxep" onchange="funSapXep(this.value);">
					<option value="0" <? if($sid==0){?> selected="selected" <? }?>>--- Tất cả ---</option>
					<option value="1" <? if($sid==1){?> selected="selected" <? }?>>Mới cập nhật</option>
					<option value="2" <? if($sid==2){?> selected="selected" <? }?>>Mới đăng bán</option>
					<option value="3" <? if($sid==3){?> selected="selected" <? }?>>Giá tăng dần</option>
					<option value="4" <? if($sid==4){?> selected="selected" <? }?>>Giá giảm dần</option>
				</select>           
            </li>    
        </ul>

        <br class="clearBoth" style="font-size:0pt;"/>
    </div>
    <div class="corner-round-04-bottom-right">
        <div class="corner-round-04-bottom-left">
            <div class="corner-round-04-bottom-bg"></div>
        </div>
    </div>   
</div> 
<div id="ctl00_idMainHolder_idProductBookmark_idListPanel">
	
    <div id="product-list">

        <div id="product-list-header">       
            <div class="product-col product-col-name">
                <p>Tên sản phẩm</p>
            </div>
            <div class="product-col product-col-price">
                <p>Giá bán</p>
            </div>
            <div class="product-col product-col-region">

                <p>Xóa</p>
            </div>
        </div>
        <div style="clear:both;height:4px;font-size:0pt;"></div>
        <div id="product-list-body">
            <div class="corner-round-05-top-right">
                <div class="corner-round-05-top-left">
                    <div class="corner-round-05-top-bg"></div>

                </div>
            </div>
            <div class="corner-round-05-body2">            
                <div id="products-list" style="height:auto;overflow:hidden">    
                    
               <?
			   		if($u_sanphamluu != ""){
					$st = 0;
					while($row = $db->fetch_array($rs)){
					$st++;
					$t_id = $row[t_id];	
					$t_nguoidang = $row[t_nguoidang];
					$t_ten_nguoidang = tenNguoiDung($t_nguoidang);
					$t_tieude = $myString->unQuote(stripslashes($row[t_tieude]));
					$t_hinhanh = $PathThumbFile . $row[t_hinhanh];
					$t_mota = $myString->unQuote(stripslashes($row[t_mota]));
					$t_giaban = showprice($row[t_giaban]);
					$t_loaitien = loadLoaiTien($row[t_loaitien]);		
					$t_tinhthanh = layTinhThanh($row[t_tinhthanh]);
					$t_solanxem = $row[t_solanxem];
					//$t_khuyenmai = $row[t_khuyenmai];
					//$t_dacbiet = $row[t_dacbiet];
					$t_xemgannhat = format_date_time($row[t_xemgannhat]);
					$comment = loadSoComment($t_id);
			   ?>            
						   
						    <div class="product-item-rows">
                               <ul>
                                    <li class="product-item-col-picture">
                                        <p> 
                                            <a title="<?=$t_tieude?>" href="<?=$root?>/chi-tiet-san-pham/<?=$t_id?>/<?=$myString->vietdecode($t_tieude)?>" class="tips product-name">
                                                <img width="100px" style="vertical-align:middle" alt="Xem chi tiết" height="100px" src="<?=$root?>/<?=$t_hinhanh?>" onerror="this.src='<?=$root?>/themes/images/noimg.jpg';"/></a>
                                        </p>                        
                                    </li>
                                    <li class="product-item-col-name">
                                        <h1>
                                            <a href="<?=$root?>/chi-tiet-san-pham/<?=$t_id?>/<?=$myString->vietdecode($t_tieude)?>" class="product-name" title="Xem chi tiết"><?=$t_tieude?></a>
                                        </h1> 
                                        <p class="truncate" style="text-align:left;">
                                           <?=$t_mota?>
                                        </p>                                                  
                                        <p style="padding-bottom:5px;">

                                            Shop: <a class="seller popup-profile" href="<?=$root?>/shop-<?=$t_nguoidang?>/<?=tenNguoiDung2($t_nguoidang)?>"><?=$t_ten_nguoidang?></a>      
                                        </p> 
                                        <p style="font-size:8pt;color:Gray;">
                                            <?=$t_xemgannhat?> | Lượt xem: <?=$t_solanxem?> | Comments: <?=$comment?>
                                        </p>                                                      
                                    </li>
                                    <li class="product-item-col-price">
                                        <p>
                                            <?=$t_giaban?>&nbsp;<?=$t_loaitien?>                                        
                                        </p>

                                    </li>
                                    <li class="product-item-col-region">
                                        <p>
                                            <a href="<?=$root?>/?mod=sanphamluu&p=<?=$p?>&act=delete&pid=<?=$t_id?>" style="color:#0000ff;">Xóa</a>
                                        </p>
                                    </li>
                                </ul>                                                       
                            </div>  
                            
							<?
								if($st != $db->num_rows($rs)){
							?>
                                <div class="product-list-sep">&nbsp;</div> 
							
							<? } ?>	
          
               	<? }?>
				
			   <? }else{ ?>             
			   
			   <p align="center">Chưa có sản phẩm nào được lưu !</p>
			   
			   <? } ?>
                           
                                                         
                </div>
            </div>
            <div class="corner-round-05-bottom-right">
                <div class="corner-round-05-bottom-left">
                    <div class="corner-round-05-bottom-bg"></div>
                </div>
            </div>    
        </div>

        <div id="product-list-footer"></div>
    </div>
    <? 
		if($u_sanphamluu != ""){
	?>
		<p align="center" class="font">
			<?php echo page_div( "".$root."/?mod=sanphamluu&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
		 </p>
	 <br />		 <br />	
	 <? } ?>
    <!-- } Product List -->

</div>

                
        </div>                
    </div>
    <div style="clear:both;"></div>      
    <!-- } Main Page-Content -->  

            </div>
